package array;

/**
 * @author wangtianqi
 */
public class ArrTest {

    public static void main(String[] args) {
        int[] test = {0, 1, 2, 2, 3, 0, 4, 2};
        System.out.println(removeElement(test, 2));
    }

    /**
     * 27. 移除元素
     * @param nums
     * @param val
     * @return
     */
    public static int removeElement(int[] nums, int val) {
        int p0 = 0;
        int p1 = 0;
        while (p1 < nums.length) {
            if (nums[p1] != val) {
                nums[p0++] = nums[p1];
            }
            p1++;
        }
        return p0;
    }
}
